package cn.edu.jou.cs.course.springboot.addersim;

import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.MustacheFactory;

import cn.edu.jou.cs.course.springboot.addersim.halfadder.Adder;
import cn.edu.jou.cs.course.springboot.addersim.halfadder.Input;
import cn.edu.jou.cs.course.springboot.addersim.halfadder.Output;
import cn.edu.jou.cs.course.springboot.addersim.mustache.HalfAdderInputOutput;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Simulator {
    public static void main(String[] args) throws IOException {
        Adder halfAdder = new Adder();

        List<HalfAdderInputOutput> inputOutputList = new ArrayList<>();
        for (int augend = 0; augend <= 1; augend++) {
            for (int addend = 0; addend <= 1; addend++) {
                Input input = new Input(Signal.valueOf(augend), Signal.valueOf(addend));
                Output output = halfAdder.add(input);
                inputOutputList.add(new HalfAdderInputOutput(input, output));
            }
        }
        Map<String, Object> scopes = new HashMap<String, Object>();
        scopes.put("inputOutputList", inputOutputList);
        MustacheFactory mf = new DefaultMustacheFactory();
        Mustache mustache = mf.compile("halfadder_truth_table.mustache");
        mustache.execute(new PrintWriter(System.out), scopes).flush();


        // TODO: output full adder truth table
    }
}
